﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using OTS.Model;
using OTS.BLL;

public partial class page_brand : System.Web.UI.Page
{
    Brand brand = new Brand();
    BrandBLL brandBLL = new BrandBLL();
    ProductBLL proBLL = new ProductBLL();
    ProductTypeBLL proTypeBLL = new ProductTypeBLL();
    DataTable dt = new DataTable();
    DataTable dTable = new DataTable();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.QueryString["brandID"] != null)
            {
                string brandID = Request.QueryString["brandID"];

                brand = brandBLL.GetByBrand(Int32.Parse(brandID));
                this.imgTopBrand.ImageUrl = brand.brand_toplogo;
                if (brand.brand_topshow!="")
                {
                    this.Image1.ImageUrl = brand.brand_topshow;
                }
                else
                {
                    this.Image1.ImageUrl = "img/yes_picture.gif";
                }
                this.lblDes.Text = brand.des;
                this.lblBrand.Text = brand.brand_name;
                BindExpirySeason();
                BindType();
                McontentList();
            }
        }
    }

    //绑定季节
    protected void BindExpirySeason()
    {
        string ExpirySeasonFile = Server.MapPath("XML/ExpirySeason.xml");
        DataSet ds = new DataSet();
        ds.ReadXml(ExpirySeasonFile);
        dt = ds.Tables[0];
        this.rpExpirySeason.DataSource = dt;
        this.rpExpirySeason.DataBind();
    }

    //绑定款式
    protected void BindType()
    {
        dt = proTypeBLL.GetAllType();
        this.rpType.DataSource = dt;
        this.rpType.DataBind();
    }

    protected void McontentList()
    {
        System.Text.StringBuilder sb = new System.Text.StringBuilder();
        dt = proTypeBLL.GetAllType();
        string strUrl = "";
        string strImgUrl = "";
        string brandID = Request.QueryString["brandID"];

        dTable = proBLL.GetBrandByProduct(Int32.Parse(brandID));
        sb.Append("<div class='mcontent'>");
        sb.Append("<div class='mtitle'>");
        sb.Append("<h2>新品</h2>");
        sb.Append("<div class='imore'>");
        sb.Append("<a href='new-product.aspx' target='_blank'>更多&raquo;</a>");
        sb.Append("</div>");
        sb.Append("</div>");
        sb.Append("<div class='productSYS'>");
        sb.Append("<ul>");

        for (int k = 0; k < dTable.Rows.Count; k++)
        {
            sb.Append("<li>");
            sb.Append("<div style='overflow: hidden; text-align: center; vertical-align: middle;'>");
            sb.AppendFormat("<a title='{0}{1}' target='_blank' href='product.aspx?proID={2}'>", dTable.Rows[k]["title"].ToString(), dTable.Rows[k]["proNO"].ToString(), dTable.Rows[k]["proID"].ToString());
            if (dTable.Rows[k]["bigImg_pic"].ToString()=="")
            {
                strImgUrl = "img/yes_picture.gif";
            }
            else
            {
                strUrl = dTable.Rows[k]["bigImg_pic"].ToString().Replace("\\", "/");
                strImgUrl = strUrl.Replace("~/", "");
            }
            sb.AppendFormat("<img title='{0}{1}' src='{2}' />", dTable.Rows[k]["title"].ToString(), dTable.Rows[k]["proNO"].ToString(), strImgUrl);
            sb.Append("</a>");
            sb.Append("</div>");
            sb.Append("<h6>");
            sb.AppendFormat("<a title='{0}{1}' target='_blank' href='product.aspx?proID={2}'>", dTable.Rows[k]["title"].ToString(), dTable.Rows[k]["proNO"].ToString(), dTable.Rows[k]["proID"].ToString());
            sb.AppendFormat("{0}{1}", dTable.Rows[k]["title"].ToString(), dTable.Rows[k]["proNO"].ToString());
            sb.Append("</a>");
            sb.Append("</h6>");
            sb.Append("<ul><li>");
            sb.AppendFormat("<span style='color: default;' class='price1'>￥{0}</span>", dTable.Rows[k]["retailPrice"].ToString());
            sb.AppendFormat("<span style='color: default;' class='mktprice1'>￥{0}</span>", dTable.Rows[k]["wholeSalePrice"].ToString());
            sb.Append("</li></ul>");
            sb.Append("</li>");
        }

        sb.Append("</ul>");
        sb.Append("</div>");
        sb.Append("</div>");

        for (int i = 0; i < dt.Rows.Count; i++)
        {
            sb.Append("<div class='mcontent'>");
            sb.Append("<div class='mtitle'>");
            sb.AppendFormat("<h2>{0}</h2>", dt.Rows[i]["typeName"].ToString());
            sb.Append("<div class='imore'>");
            sb.AppendFormat("<a href='gallery-grid.aspx?typeID={0}' target='_blank'>更多&raquo;</a>", dt.Rows[i]["typeId"].ToString());
            sb.Append("</div>");
            sb.Append("</div>");
            sb.Append("<div class='productSYS'>");
            sb.Append("<ul>");

            dTable = proBLL.GetBrandByProduct(Convert.ToInt32(brandID),Convert.ToInt32(dt.Rows[i]["typeId"].ToString()));
            for (int j = 0; j < dTable.Rows.Count; j++)
            {
                sb.Append("<li>");
                sb.Append("<div style='overflow: hidden; text-align: center; vertical-align: middle;'>");
                sb.AppendFormat("<a title='{0}{1}' target='_blank' href='product.aspx?proID={2}'>", dTable.Rows[j]["title"].ToString(), dTable.Rows[j]["proNO"].ToString(), dTable.Rows[j]["proID"].ToString());
                if (dTable.Rows[j]["bigImg_pic"].ToString() == "")
                {
                    strImgUrl = "img/yes_picture.gif";
                }
                else
                {
                    strUrl = dTable.Rows[j]["bigImg_pic"].ToString().Replace("\\", "/");
                    strImgUrl = strUrl.Replace("~/", "");
                }
                sb.AppendFormat("<img title='{0}{1}' src='{2}' />", dTable.Rows[j]["title"].ToString(), dTable.Rows[j]["proNO"].ToString(), strImgUrl);
                sb.Append("</a>");
                sb.Append("</div>");
                sb.Append("<h6>");
                sb.AppendFormat("<a title='{0}{1}' target='_blank' href='product.aspx?proID={2}'>", dTable.Rows[j]["title"].ToString(), dTable.Rows[j]["proNO"].ToString(), dTable.Rows[j]["proID"].ToString());
                sb.AppendFormat("{0}{1}", dTable.Rows[j]["title"].ToString(), dTable.Rows[j]["proNO"].ToString());
                sb.Append("</a>");
                sb.Append("</h6>");
                sb.Append("<ul><li>");
                sb.AppendFormat("<span style='color: default;' class='price1'>￥{0}</span>", dTable.Rows[j]["retailPrice"].ToString());
                sb.AppendFormat("<span style='color: default;' class='mktprice1'>￥{0}</span>", dTable.Rows[j]["wholeSalePrice"].ToString());
                sb.Append("</li></ul>");
                sb.Append("</li>");
            }
            sb.Append("</ul>");
            sb.Append("</div>");
            sb.Append("</div>");
            this.Mcontent.InnerHtml = sb.ToString();
        }
    }
    protected void lbtnBrand_Click(object sender, EventArgs e)
    {
        Response.Redirect("page-brand.aspx?brandID=" + Request.QueryString["brandID"]);
    }

    protected void lbtnExpirySeason_Click(object sender, EventArgs e)
    {
        string expirySeason = ((LinkButton)sender).CommandArgument;
        Response.Redirect("gallery-grid.aspx?brandID=" + Request.QueryString["brandID"] + "&expirySeason=" + expirySeason);
    }

    protected void lbtnType_Click(object sender, EventArgs e)
    {
        string type = ((LinkButton)sender).CommandArgument;
        Response.Redirect("gallery-grid.aspx?brandID=" + Request.QueryString["brandID"] + "&typeID=" + type);
    }
}
